package edu.vital.energy.longevity.ch10.config;

import org.springframework.cache.interceptor.KeyGenerator;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

/**
 * 自定义缓存键生成器
 */
@Component("customKeyGenerator")
public class CustomKeyGenerator implements KeyGenerator {
    @Override
    public Object generate(Object target, Method method, Object... params) {
        // 将方法名和参数值组合生成缓存键
        StringBuilder keyBuilder = new StringBuilder();
        keyBuilder.append(method.getName());
        
        for (Object param : params) {
            keyBuilder.append(":").append(param);
        }
        
        return keyBuilder.toString();
    }
}